package com.kongxx.wicketstudy.validating;

import java.util.HashMap;
import java.util.Map;
import java.io.Serializable;

public class Request implements Serializable {

	private int weight;
	private String patronCode;
	private static Map patronCodeToDiscount;
	

	static {
		patronCodeToDiscount = new HashMap();
		patronCodeToDiscount.put("p1", new Integer(90));
		patronCodeToDiscount.put("p2", new Integer(95));
	}

	public Request(int weight, String patronCode) {
		this.weight = weight;
		this.patronCode = patronCode;
	}

	public String getPatronCode() {
		return patronCode;
	}

	public void setPatronCode(String patronCode) {
		this.patronCode = patronCode;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public int getPostage() {
		Integer discount = (Integer) patronCodeToDiscount.get(patronCode);
		int postagePerKg = 10;
		int postage = weight * postagePerKg;
		if (discount != null) {
			postage = postage * discount.intValue() / 100;
		}
		return postage;
	}

	public static boolean isPatronCodeValid(String patronCode) {
		return patronCode == null || patronCodeToDiscount.containsKey(patronCode);
	}
}
